package easy;

import util.PrintUtils;

public class Solution_1103 {

    public int[] distributeCandies(int candies, int num_people) {
        int tempSum = (1 + num_people) * num_people / 2;
        int count = 0, temp = candies;
        int nextSum = tempSum;
        for (; temp >= nextSum; ) {
            temp -= nextSum;
            count++;
            nextSum = tempSum + num_people * num_people * count;
        }
        int[] res = new int[num_people];
        for (int i = 0; i < res.length; i++) {
            if (count > 0) {
                res[i] = (i + 1) * count + num_people * (count - 1) * count / 2;
            }
            if (temp > 0) {
                int sub = Math.min(i + 1 + num_people * count, temp);
                res[i] += sub;
                temp -= sub;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Solution_1103 model = new Solution_1103();
        PrintUtils.arrayInt(model.distributeCandies(60, 4));
        PrintUtils.arrayInt(model.distributeCandies(7, 4));
        PrintUtils.arrayInt(model.distributeCandies(10, 3));
        PrintUtils.arrayInt(model.distributeCandies(22, 4));
    }
}
